/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Attributes;

import Attributes.SaveFeedData;
import Attributes.FeedDataKeys;
import Attributes.FeedDataValues;
import Attributes.websiteDataExtract;
import java.util.ArrayList;

/**
 *
 * @author Alexander
 */
public class SendFeedData extends Thread {

    ArrayList<FeedDataKeys> keys;
    SaveFeedData saveData;
    String site;
    String docSelect;
    String docAttribute;

    @Override
    public void run() {
        System.out.println("SendFeedData.run()");

        saveData = new SaveFeedData();
        keys = new ArrayList<>();
        String UrlPath, Location, Token, xpathTitle, xpathArtist;
        int numOfSongs;
        int numVar = 0;
        String[][] RssString;
        String InType;
        String Order = null;

        //Meaning:  keys.add(new FeedDataKeys(UrlPath, Location, Token, xpathTitle, xpathArtist, InType, RssString, numOfSongs, numVar, Order));
        keys.add(new FeedDataKeys("http://www.billboard.com/rss/charts/hot-100", "Billboard-Pop", ",", "rss/channel/item/title", "rss/channel/item/artist", "XML", null, 100, 2, null));
        keys.add(new FeedDataKeys("http://www.billboard.com/rss/charts/dance-electronic-songs", "Billboard-EDM", ",", "rss/channel/item/title", "rss/channel/item/artist", "XML", null, 25, 2, null));
        keys.add(new FeedDataKeys("http://www.billboard.com/rss/charts/country-songs", "Billboard-Country", ",", "rss/channel/item/title", "rss/channel/item/artist", "XML", null, 25, 2, null));
        keys.add(new FeedDataKeys("http://www.billboard.com/rss/charts/r-b-hip-hop-songs", "Billboard-RnB", ",", "rss/channel/item/title", "rss/channel/item/artist", "XML", null, 25, 2, null));
        keys.add(new FeedDataKeys("http://hypem.com/feed/popular/feed.xml", "Hypem", "~", "rss/channel/item/title", "rss/channel/item/title", "XML", null, 20, 1, "Artist_Title"));
        keys.add(new FeedDataKeys("https://itunes.apple.com/us/rss/topsongs/limit=40/xml", "Itunes-Pop", "~", "feed/entry/title", "feed/entry/title", "XML", null, 40, 1, "Title_Artist"));
        keys.add(new FeedDataKeys("https://itunes.apple.com/us/rss/topsongs/limit=40/genre=6/xml", "Itunes-Country", "~", "feed/entry/title", "feed/entry/title", "XML", null, 40, 1, "Title_Artist"));
        keys.add(new FeedDataKeys("https://itunes.apple.com/us/rss/topsongs/limit=40/genre=15/xml", "Itunes-RnB", "~", "feed/entry/title", "feed/entry/title", "XML", null, 40, 1, "Title_Artist"));
        keys.add(new FeedDataKeys("https://itunes.apple.com/us/rss/topsongs/limit=40/genre=7/xml", "Itunes-EDM", "~", "feed/entry/title", "feed/entry/title", "XML", null, 40, 1, "Title_Artist"));
        keys.add(new FeedDataKeys("http://www.bbc.co.uk/radio1/chart/singles", "UK40", "||", null, null, "String", websiteDataExtract.webExtractToArray("http://www.bbc.co.uk/radio1/chart/singles", "div[class = p-f p-f-v1 p-f-variant-small p-f-p_playlister  p-f-lang-en-gb]", "data-title", 40, "||", "UK40"), 40, 2, "Title_Artist"));
        keys.add(new FeedDataKeys("http://www.shazam.com/charts/us_top_100", "Shazam", "-", null, null, "String", websiteDataExtract.webExtractToArray("http://www.shazam.com/charts/us_top_100", "img[itemprop=image]", "alt", 100, "-", "Shazam"), 100, 2, "Artist_Title"));
        keys.add(new FeedDataKeys("http://www.beatport.com/top-100", "Beatport", "-", null, null, "String", websiteDataExtract.webExtractToArray("http://www.beatport.com/top-100", "span[class = play-queue play-queue-med-small]", "data-json", 100, "-", "Beatport"), 100, 2, "Artist_Title"));
        startExtraction();
    }

    public void startExtraction() {
        System.out.println("SendFeedData.startExtraction()");

        for (FeedDataKeys key : keys) {
            saveData.ReadRunner(key);
        }
        int feedDataSize = saveData.getFeedData().size();
        ArrayList<FeedDataValues> feedData = saveData.getFeedData();
        for (int y = 0; y < feedDataSize; y++) {
            feedData.get(y).insertFeedData();
        }
        System.out.println("RSS Import Complete!");
        //RecordsMain.getUI.setVisible(true);
    }
}
